package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetMessegerTwoGroupsRequest;
import keeto.com.vn.bms.network.response.GetMessgerTwoGroupsResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetMessegerTwoGroups extends AbstractTask{

	private String Objid;
	private String AuthKey;
	private int pageNumber;
	private int pageLimit;



	public TaskGetMessegerTwoGroups(BMSListener listener, IBMSCore core,
			String objid, String authKey, int pageNumber, int pageLimit) {
		super(listener, core);
		Objid = objid;
		AuthKey = authKey;
		this.pageNumber = pageNumber;
		this.pageLimit = pageLimit;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetMessegerTwoGroupsRequest request = new GetMessegerTwoGroupsRequest();
		request.setObjID(Objid);
		request.setAuthKey(AuthKey);
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetMessgerTwoGroupsResponse response = protocol.GetMessgerHome(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetMessegerTwoGroups(response.getReturnCode(),response.getPageCount(),response.getArrMsg());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetMessegerTwoGroups(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, IBMSConfig.UNINITIALIZED_INT,null);
		}
	}

}
